{%extends file="base_content.html"%}
{%block name="breadcrumb"%}
<li class="active">模块管理</li>
{%/block%}

{%block name="content"%}

<div class="page-header">

    <div class="row">
        <div class="col-xs-1" style="min-width: 80px">
            <a href="index.php?c=sys_module&m=add" class="btn btn-success btn-sm">
                <i class="ace-icon fa fa-plus bigger-110"></i>新建
            </a>


        </div>
        <div class="col-xs-1" style="min-width: 80px">


            <a id="sort_save" href="javascript:saveSort()" class="btn  btn-sm disabled">
                <i class="ace-icon fa fa-save bigger-110"></i>保存排序
            </a>
        </div>


    </div>


</div>

<table id="myTable" class="table table-striped table-bordered table-hover">
    <thead>
    <tr>


        <th>模块名称</th>
        <th style="width: 90px">操作</th>
    </tr>
    </thead>

    <tbody id="sortable1">
    {%foreach from=$list item=value%}
    <tr>
        <td colspan="2">


            <table class="table table-striped table-bordered table-hover" style="margin: 0">
                <tr>

                    <td><a href="#" class="portlet-header" module="module" value="{%$value.id%}"><i
                            class="ace-icon fa fa-arrows bigger-110"></i> {%$value.module_name%}</a></td>


                    <td style="width: 90px">
                        <div class="action-buttons">

                            <a class="orange"
                               href="index.php?c=sys_module&m=add&parent_id={%$value.id%}&module_type=page"
                               title="添加页面">
                                <i class="ace-icon fa fa-plus bigger-130"></i>
                            </a>

                            <a class="green" href="index.php?c=sys_module&m=edit&id={%$value.id%}">
                                <i class="ace-icon fa fa-pencil bigger-130"></i>
                            </a>

                            <div class="inline position-relative">

                                <a href="#" class="red dropdown-toggle" data-toggle="dropdown" data-position="auto">
                                    <i class="ace-icon fa fa-trash-o icon-only bigger-130"></i>
                                </a>

                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                    <li>
                                        <a href="javascript:void(0)" onclick="deleteEntity('{%$value.id%}',this)"
                                           class="tooltip-error" data-rel="tooltip" title=""
                                           data-original-title="Delete">
                                <span class="red">
                                    <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>

                        </div>
                    </td>
                </tr>
                {%if !empty($value.children)>0%}

                <tr>
                    <td colspan="2">
                        <table class="table table-striped table-bordered"
                               style="margin-bottom: 0px;width: 90%;float: right">

                            <tbody id="sortable_{%$value@index%}">
                            {%foreach from=$value.children item=page%}
                            <tr>
                                <td>


                                    <table class="table table-striped table-bordered" style="margin: 0">
                                        <tr>
                                            <td><a href="#" class="portlet-header1" module="page" value="{%$page.id%}"><i
                                                    class="ace-icon fa fa-arrows bigger-110"></i> {%$page.module_name%}</a>
                                            </td>

                                            <td>
                                                {%$page.module_resource%}
                                            </td>


                                            <td style="width: 90px">

                                                <div class="action-buttons">

                                                    <a class="orange"
                                                       href="index.php?c=sys_module&m=add&parent_id={%$page.module_parent_id%}&module_type=action"
                                                       title="添加功能">
                                                        <i class="ace-icon fa fa-plus bigger-130"></i>
                                                    </a>

                                                    <a class="green"
                                                       href="index.php?c=sys_module&m=edit&id={%$page.id%}&module_type=action&parent_id={%$page.module_parent_id%}">
                                                        <i class="ace-icon fa fa-pencil bigger-130"></i>
                                                    </a>

                                                    <div class="inline position-relative">

                                                        <a href="#" class="red dropdown-toggle" data-toggle="dropdown"
                                                           data-position="auto">
                                                            <i class="ace-icon fa fa-trash-o icon-only bigger-130"></i>
                                                        </a>

                                                        <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                                            <li>
                                                                <a href="javascript:void(0)"
                                                                   onclick="deleteEntity('{%$page.id%}',this)"
                                                                   class="tooltip-error" data-rel="tooltip" title=""
                                                                   data-original-title="Delete">
                                <span class="red">
                                    <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                </span>
                                                                </a>
                                                            </li>
                                                        </ul>
                                                    </div>

                                                </div>

                                            </td>
                                        </tr>
                                        {%if !empty($page.children)>0%}
                                        <tr>
                                            <td colspan="3">
                                                <table class="table table-striped table-bordered"
                                                       style="margin-bottom: 0px;width: 90%;float: right">
                                                    <tbody>
                                                    {%foreach from=$page.children item=action%}
                                                    <tr>
                                                        <td>{%$action.module_name%}</td>

                                                        <td>
                                                            {%$action.module_resource%}
                                                        </td>


                                                        <td style="width: 70px">

                                                            <div class="action-buttons">


                                                                <a class="green"
                                                                   href="index.php?c=sys_module&m=edit&id={%$action.id%}&parent_id={%$action.module_parent_id%}">
                                                                    <i class="ace-icon fa fa-pencil bigger-130"></i>
                                                                </a>

                                                                <div class="inline position-relative">

                                                                    <a href="#" class="red dropdown-toggle"
                                                                       data-toggle="dropdown" data-position="auto">
                                                                        <i class="ace-icon fa fa-trash-o icon-only bigger-130"></i>
                                                                    </a>

                                                                    <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                                                        <li>
                                                                            <a href="javascript:void(0)"
                                                                               onclick="deleteEntity('{%$action.id%}',this)"
                                                                               class="tooltip-error" data-rel="tooltip"
                                                                               title="" data-original-title="Delete">
                                <span class="red">
                                    <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                </span>
                                                                            </a>
                                                                        </li>
                                                                    </ul>
                                                                </div>

                                                            </div>

                                                        </td>
                                                    </tr>
                                                    {%/foreach%}
                                                    </tbody>
                                                </table>
                                            </td>
                                        </tr>
                                        {%/if%}
                                    </table>


                                </td>
                            </tr>
                            {%/foreach%}

                            </tbody>
                        </table>
                    </td>
                </tr>
            </table>


        </td>
    </tr>

    {%/if%}

    {%foreachelse%}
    {%include file="inc_gritter.html"%}
    {%/foreach%}
    </tbody>
</table>


{%/block%}
{%block name="js"%}


<script>
    function deleteEntity(id, btn) {


        $.get("index.php?c=sys_module&m=delete&id=" + id, function (r) {
            if (r == '{%$smarty.const.STATUS_SUCCESS%}') {
                tr_row = btn.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
                list_table = tr_row.parentNode;
                list_table.removeChild(tr_row);
            } else {
                alert("删除失败");
            }
        });

    }
    $(function () {
        $("#sortable1").sortable({
            update: function (event, ui) {
                $("#sort_save").removeClass('disabled');
                $("#sort_save").addClass('btn-warning');
            },
            handle: ".portlet-header"
        });
        $('tbody[id^=sortable_]').sortable({
            update: function (event, ui) {
                $("#sort_save").removeClass('disabled');
                $("#sort_save").addClass('btn-warning');
            },
            handle: ".portlet-header1"
        });

//        $( "#sortable" ).disableSelection();
    });
    function saveSort() {

        var idlist = "";
        var s = "";
        var data = {};
        $("#sortable1").find("a[module='module']").each(function () {
            if (idlist != "") {
                s = "|";
            }
            idlist = idlist + s + $(this).attr('value');
        });

        data['module'] = idlist;

        idlist = "";
        s = "";
        $("#sortable1").find("a[module='page']").each(function () {
            if (idlist != "") {
                s = "|";
            }
            idlist = idlist + s + $(this).attr('value');
        });
        data['page'] = idlist;


        $.post("index.php?c=sys_module&m=sort",data, function (r) {

            if (r == '{%$smarty.const.STATUS_SUCCESS%}') {

                $("#sort_save").removeClass('btn-warning');
                $("#sort_save").addClass('disabled');
            }else{
                alert("操作失败");
            }
        });
    }
</script>
{%/block%}

